package com.coding.service.impl;

import com.coding.base.pojo.BaseModel;
import com.coding.dao.MainPlaceDao;
import com.coding.dao.PlaceDao;
import com.coding.dao.PoemwayDao;
import com.coding.pojo.MainPlace;
import com.coding.pojo.Place;
import com.coding.pojo.Poemway;
import com.coding.service.PoemwayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auther wangchenghao
 * @date 2020/7/30
 **/
@Service
public class PoemwayImpl implements PoemwayService {
    @Autowired
    PoemwayDao poemwayDao;
    @Autowired
    MainPlaceDao mainPlaceDao;
    @Autowired
    PlaceDao placeDao;

    @Override
    public void getallways(BaseModel baseModel) throws Exception {
        List<Poemway> poemwayList = poemwayDao.selectAll();

        for (Poemway poemway : poemwayList
        ) {
            MainPlace mainPlace = new MainPlace();
            mainPlace.setMain_way_id(poemway.getWay_id());
            List<MainPlace> mainPlaceList = mainPlaceDao.queryAll(mainPlace);
            poemway.setMainPlaceList(mainPlaceList);
            List<Place> placeList=placeDao.selectByWayId(poemway.getWay_id());
            if (placeList!=null){
                poemway.setPlaceList(placeList);
            }
            List<String> placeKinds=placeDao.selectWayPlaceKind(poemway.getWay_id());
            if (placeKinds!=null){
                poemway.setPlaceKind(placeKinds);
            }

        }
        if (poemwayList.size() > 0) {
            baseModel.setSucceed("成功获得所有诗路信息", poemwayList);
        } else {
            baseModel.setFailure("获得所有诗路信息失败");
        }
    }

    @Override
    public void getwaywithmain(int main_way_id, BaseModel baseModel) throws Exception {
        Poemway poemway = poemwayDao.selectByPrimaryKey(main_way_id);
        if (poemway == null) {
            baseModel.setFailure("没有找到该诗路");
            return;
        }
        MainPlace mainPlace = new MainPlace();
        mainPlace.setMain_way_id(main_way_id);
        List<MainPlace> mainPlaceList = mainPlaceDao.queryAll(mainPlace);
        List<Place> placeList=placeDao.selectByWayId(main_way_id);
        if (placeList!=null){
            poemway.setPlaceList(placeList);
        }
        List<String> placeKinds=placeDao.selectWayPlaceKind(main_way_id);
        if (placeKinds!=null){
            poemway.setPlaceKind(placeKinds);
        }

        if (mainPlaceList.size() > 0) {
            poemway.setMainPlaceList(mainPlaceList);
            baseModel.setSucceed("获取诗路信息,主要景点,特殊景点信息和坐标", poemway);
        } else {
            baseModel.setFailure("获取诗路主要景点失败");
        }

    }
}
